package cn.imu.appdevexperiment2020.work04.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.imu.appdevexperiment2020.R;
import cn.imu.appdevexperiment2020.work04.UserBean;

public class ItemAdapter extends BaseAdapter {
    private List<UserBean> data;
    private Context context;

    public ItemAdapter(List<UserBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.view_item_userlist_layout, viewGroup, false);
            viewHolder.xingming = view.findViewById(R.id.xingming);
            viewHolder.xuehao = view.findViewById(R.id.xuehao);
            viewHolder.dianhua = view.findViewById(R.id.dianhau);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        //TextView textview = view.findViewById(R.id.text);
        //textview.setText(data.get(i).getName());
        viewHolder.xingming.setText(" 姓名: " + data.get(i).getUsername());
        viewHolder.xuehao.setText(" 学号: " + data.get(i).getUserid());
        viewHolder.dianhua.setText(" 电话: " + data.get(i).getPhonenumber());

        return view;
    }


    private final class ViewHolder {
        TextView xingming;
        TextView xuehao;
        TextView dianhua;
    }

}
